package dao.impl;

import java.util.List;

import libs.Constants;
import libs.Global;
import models.Department;
import dao.DepartmentDao;

public class DepartmentDaoImpl implements DepartmentDao {

	@Override
	public List<Department> selectList(int page) {
		int limit = Constants.NUMBER_OF_RECORD;
		int offset = (page - 1) * limit;
		return Global.entityManager.createQuery("SELECT depart FROM Department AS depart", Department.class)
				.setFirstResult(offset).setMaxResults(limit).getResultList();
	}

	@Override
	public void insertOrUpdate(Department department) {
		Global.entityManager.getTransaction().begin();
		Global.entityManager.persist(department);
		Global.entityManager.getTransaction().commit();
	}

	@Override
	public void delete(Department department) {
		Global.entityManager.getTransaction().begin();
		Global.entityManager.remove(department);
		Global.entityManager.getTransaction().commit();

	}
}
